home *** CD-ROM | disk | FTP | other *** search
/ Aminet 37 / Aminet 37 (2000)(Schatztruhe)[!][Jun 2000].iso / Aminet / util / boot / RA_USCleaner.lha / USCleaner next >
Text File  |  2000-04-11  |  14KB  |  516 lines

  1. /*
  2.    $VER: RA_USCleaner v1.1 (11.4.2000) © by Nils Görs
  3.  
  4. known bugs:
  5. - It is not possible to display "" in the textfield gadget correctly.
  6.  
  7. This script needs the rexxtricks.library
  8. */
  9.  
  10. UserStartup    = "S:User-Startup"    /* which textfile should be used? */
  11. QuickEnd    = "YES"            /* quit program with [ESC] (YES|NO) */
  12. HorizLine    = "YES"            /* use horizontal line in liestview (YES|NO) ? */
  13.  
  14. /* window dimension */
  15. TopNum        = 0
  16. LeftNum        = 0
  17. HeightNum    = 200
  18. WidthNum    = 600
  19. windowPos    = "DEFAULT"        /* DEFAULT = TopNum/LeftNum/heightNum/WidthNum
  20.                        fs = fullscreen, cs = centerscreen
  21.                        tl = topleft, cm = centermouse */
  22.  
  23. /* Don't change anything under this line
  24.    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  25. OPTIONS RESULTS
  26.  
  27. parse source . . called .
  28. PARSE ARG PubScreen
  29. IF PubScreen = "" THEN PubScreen = "Workbench"
  30.  
  31. call _InitAll()
  32. call BuildGUI()
  33.  
  34. Loop:
  35. do while ~eof(ca)
  36. call topipe('tick 50')
  37. in= readln(ca)
  38.  
  39. /*listviews need five values parsed. For string gadgets you want everything after in2 */
  40. parse var in in1 in2 in3 in4 in5 .
  41. parse var in . . infromstring
  42.  
  43. /*handle help display delay*/
  44. if delaybub>0 then do
  45.     delaybub=delaybub-1
  46.     /* if we reach zero display the help bubble*/
  47.     if delaybub=0 then do
  48.     bubleon=newbub
  49.     call topipe('bubble top 'bubx 'left 'buby 'gt "'help.newbub'"')
  50.     end
  51. end
  52.     SELECT
  53.         WHEN (in1='help' & helpon~=0 ) then call bubble(in2)
  54.         WHEN in1='arexx' then call RxHost()
  55.         WHEN in1='iconify' then call iconify()
  56.         WHEN in1='gadget' then call gadget()
  57. /*        WHEN in1='menu' then call menu()*/
  58.         WHEN in1='close' then EXIT()
  59.         WHEN in1='key' then call keystroke()
  60.         WHEN in1='cx' then call commodity()
  61.     OTHERWISE
  62.         NOP
  63.     END
  64.  
  65. END
  66. EXIT
  67.  
  68. _InitAll:
  69. IF show('P','USCLEANER') then DO
  70.   address USCLEANER uniconify
  71.   address USCLEANER activate
  72.   exit
  73. END
  74.  
  75. IF ~show('L','rexxsupport.library') THEN
  76. IF ~addlib('rexxsupport.library',0,-30,0) THEN
  77. exit(20)
  78.  
  79. /* Version check */
  80. ca = "THE"
  81. IF SHOWLIST('H', 'AWNPIPE') THEN res=open(ca,"awnpipe:USC/-2042/xc")
  82.     if res ~= 1 then do
  83.         requesterdata='`requestchoice "USCleaner Error"
  84. "To use this program you need AWNPipe:*n        (Vers 2.42 or newer). " "OK"`'
  85.         CALL ShellResult(requesterdata)
  86.         exit
  87.     end
  88.  
  89.    IF ~SHOW(LIBRARIES,'rexxtricks.library') THEN
  90.       IF ~ADDLIB('rexxtricks.library',9,-30,38) THEN
  91.          quit('Cannot open rexxtricks.library!',10)
  92.  
  93. /* Init variables */
  94. TRUE        = 1
  95. FALSE        = 0
  96. Counter        = 0
  97. Entries        = ""
  98. changes        = 0
  99. NL        = '0a'x
  100. delaybub    = 0
  101. helpon        = 1
  102.  
  103. schutzbits = RXTR_GETPROTECTION(UserStartup)
  104. IF Schutzbits = "" THEN DO
  105.     say UserStartup "not found."
  106.     EXIT(5)
  107. END
  108. CALL ReadUserStartup(UserStartup)
  109. CALL GetInhalt(1)
  110. RETURN
  111.  
  112. ReadUserStartup:
  113. PARSE ARG Filename
  114. IF RXTR_READFILE(Filename,Startup) = 0 THEN EXIT
  115.  
  116. more = 1
  117. a = 0
  118. c = 1            /* Nummer der Liste */
  119. i = 1
  120. DO WHILE more
  121.         nummer1 = RXTR_LSEARCH("#?;BEGIN#?",startup,i,case,pattern)
  122.         IF nummer1 = -1 THEN DO
  123.             more = 0
  124.             ITERATE
  125.         END
  126.         nummer2 = RXTR_LSEARCH("#?;END#?",startup,nummer1+1,case,pattern)
  127.         nummer3 = RXTR_LSEARCH("#?;BEGIN#?",startup,nummer1+1,case,pattern)
  128.  
  129.         IF nummer3 < nummer2 & nummer3 ~=-1 THEN say "END Fehler!"        /* BEGIN ohne END */
  130.         IF nummer2 = -1 & nummer1 ~= -1 THEN say "END Fehler #2"        /* BEGIN ohne END  im letzten Eintrag!*/
  131.  
  132.         a = a+1
  133.         num=INDEX(startup.nummer1,";BEGIN")
  134.         Eintraege.a = SUBSTR(startup.nummer1,num+7)                /* Listview mit BEGIN|END Einträgen erstellen */
  135.         Eintraege2.a = nummer1 nummer2
  136.  
  137.         Eintraege3.a = Eintraege.a a
  138.         i = nummer2+1
  139. END
  140.  
  141. Eintraege.0 = a            /* Anzahl der BEGIN|END Einträge */
  142. Eintraege2.0 = a        /* Koordinaten für Eintraege */
  143. Eintraege3.0 = a        /* Koordinaten für sortierte Eintraege */
  144.  
  145. IF Eintraege.0 = 0 THEN DO
  146.     say "You don't have 'BEGIN...END' instuctions in your User-Startup."
  147.     EXIT()
  148. END
  149.  
  150. call RXTR_QSORT(Eintraege3,,NOCASE,1," ")    /* sortiere Eintraege */
  151. RETURN
  152.  
  153. GetInhalt:
  154. PARSE ARG Nummer
  155.  
  156. Nummer1=WORD(Eintraege2.Nummer,1)
  157. Nummer2=WORD(Eintraege2.Nummer,2)
  158.  
  159.             d = 0
  160.             DO b = nummer1+1 TO nummer2-1
  161.                 d = d +1
  162.                 Inhalt.d = startup.b
  163.             END
  164.                 Inhalt.0 = d
  165. RETURN
  166.  
  167. BuildGUI:
  168. /* define window */
  169. IF windowpos = "DEFAULT" THEN Winpos = 'top='topNum 'left='leftNum 'width='widthNum 'height='heightNum 
  170.             ELSE Winpos = windowpos 'width='widthNum 'height='heightNum 
  171. call topipe('Title="USCleaner"' winpos 'st="Workbench Screen" Icontitle=USC modify help state iconifygadget sendkeys defaultgadgets SpaceInner SpaceOuter activate ii "'called'" pubscreen='pubscreen)
  172.  
  173. call topipe('ARexx gt "USCLEANER|uniconify|iconify|quit|activate|front|back"')
  174.  
  175. call topipe('layout v b=7 gt="Assigns"')
  176.     call topipe('layout h si so b=0')
  177.     IF HorizLine = "YES" THEN AssignListViewID = topipe('listbrowser lbl="" arrows h v minh 200 weiw=40')
  178.                 ELSE AssignListViewID = topipe('listbrowser lbl="" arrows minh 200 weiw=40')
  179.         help.AssignListViewID = 'Entries with all Assign found in User-Startup.*nYou can use cursor keys and Home/End to scroll*nthrough the listview.'
  180.         call topipe('WeightBar')
  181.         TextEditorID = topipe('textfield arrows h v ro')
  182.         help.TextEditorID = 'Contents of selected Assign.'
  183.     call topipe('le')
  184.  
  185.     call topipe('layout b=0 h e si so weih 0')
  186.         activeGadget = topipe('button gt "_activate" weiw 0 ')
  187.         help.activeGadget = 'Select all entries.'
  188.         deactiveGadget = topipe('button gt "_deactivate" weiw 0 ')
  189.         help.deactiveGadget = 'Deselect all entries.'
  190.         ToggleGadget = topipe('button gt "_Toggle" weiw 0 ')
  191.         help.ToggleGadget = 'Toggle state of entries.'
  192.         RemoveGadget = topipe('button gt "_Remove" weiw 0 ')
  193.         help.RemoveGadget = 'Removes the currently selected assign.'
  194.     call topipe('le')
  195.  
  196.     call topipe('layout b=0 v si so weih 0')
  197.     call topipe('button b=7 minh 2')
  198.     call topipe('layout b=0 h si so weih 0')
  199.         SaveGadget   = topipe('button gt "_Save" weiw 0 ')
  200.         help.SaveGadget = 'Saves the changed User-Startup.'
  201.         CancelGadget   = topipe('button gt "_Cancel" weiw 0 ')
  202.         help.CancelGadget = 'Nothing will be changed.'
  203.     call topipe('le')
  204.     call topipe('le')
  205. call topipe('le')
  206.  
  207. call topipe('commodity cxname USCleaner cxtitle="USCleaner (c) by Nils Görs" cxdesc="Toggle, removes BEGIN/END instructions" unique cxhotkey="ctrl alt u"')
  208.  
  209. /*open the GUI window*/
  210. call topipe("open")
  211.  
  212. /* fill Listview and Textgadget */
  213. call getListView()
  214. RETURN
  215.  
  216. getListView:
  217. call topipe('id 'AssignListViewID 'list 0')
  218.  
  219.     do i = 1 to Eintraege3.0
  220.     Anz=WORDS(Eintraege3.i)
  221.     Nodegt=SUBWORD(Eintraege3.i,1,Anz-1)
  222.         Node_ID = topipe('id 'AssignListViewID 'addnode gt "'NodeGT'"')
  223.         Counter = Counter + 1
  224.         Entries = Entries Node_ID
  225.     end
  226.  
  227. call topipe('id 'AssignListViewID 'list 1')
  228. RETURN
  229.  
  230. getTextview:
  231. PARSE ARG nummer
  232.     Anz=WORDS(Eintraege3.Nummer)
  233.     Nummer=DELWORD(Eintraege3.Nummer,1,Anz-1)
  234. call GetInhalt(Nummer)
  235.  
  236. IF Inhalt.0 ~= 0 THEN DO
  237.         meinInhalt = ""
  238.         do i = 1 to Inhalt.0
  239.  
  240.         IF Index(Inhalt.i,'"') ~= 0 THEN
  241.             Inhalt2 = COMPRESS(Inhalt.i,'"')
  242.         ELSE
  243.             Inhalt2 = Inhalt.i
  244.         meinInhalt = meinInhalt||Inhalt2||"*N"
  245.         end
  246.     call topipe('id' TextEditorID 'gt="'meinInhalt'"')
  247. END
  248. RETURN(Nummer)
  249.  
  250. topipe:
  251. /* this routine does error checking on lines written to pipe.*/
  252. /*get line to output*/
  253. parse arg out
  254.  
  255. /* write to the pipe*/
  256. call writeln(ca,out)
  257.  
  258. /*get responce and parse it.*/
  259. in=readln(ca)
  260. parse var in res1 res2 .
  261.  
  262. /* if all is ok return the second part of the responce (usualy the GID)*/
  263. if res1='ok' then return(res2)
  264.  
  265. /* something went wrong, we notify the user then exit */
  266. /*show problem line and responce (reponce may be just a blank line)*/
  267. say 'error from: 'out
  268. say '  responce: ' in
  269. exit
  270.  
  271. topipe2:
  272. /* this routine does error checking on lines written to pipe.*/
  273.  
  274. /*get line to output*/
  275. parse arg out
  276.  
  277. /* write to the pipe*/
  278. call writeln(ca,out)
  279.  
  280. /*get responce and parse it.*/
  281. in=readln(ca)
  282. parse var in res1 res2 .
  283. return(res1)
  284.  
  285. ShellResult:
  286. PARSE ARG ShellCmd
  287. cmdid='req'pragma('id')
  288. address command 'rxset' cmdid Shellcmd
  289. from_Shell=getclip(cmdid)
  290. call setclip(cmdid,'')
  291. RETURN(from_Shell)
  292.  
  293. /*
  294. *** actions
  295. */
  296. iconify:
  297. IF ARG(1) ~= "" THEN in2 = ARG(1)
  298. IF in2=1 THEN call topipe('id 0 s 32')        /* iconify   */
  299.      ELSE call topipe('id 0 s 64')        /* uniconify */
  300. RETURN
  301.  
  302. /* my very own commodity */
  303. commodity:
  304. SELECT
  305.     WHEN in2='show' then call iconify(0)
  306.     WHEN in2='hide' then call iconify(1)
  307.     WHEN in2='kill' then EXIT
  308.     WHEN in2='hotkey' then call iconify(0)
  309. OTHERWISE
  310. END
  311. RETURN
  312.  
  313. /*
  314.   my very personal ARexx host
  315. */
  316. RxHost:
  317.     call topipe2("rc 0")
  318. SELECT
  319.     WHEN in2 = 0 THEN call topipe('id 0 s 64')        /* uniconify */
  320.     WHEN in2 = 1 THEN call topipe('id 0 s 32')        /* iconify */
  321.     WHEN in2 = 2 THEN EXIT(0)                /* quit */
  322.     WHEN in2 = 3 THEN call topipe('id 0 s 1')        /* activate */
  323.     WHEN in2 = 4 THEN call topipe('id 0 s 2')        /* window to front */
  324.     WHEN in2 = 5 THEN call topipe('id 0 s 4')        /* window to back */
  325. OTHERWISE
  326.     call topipe2("rc 5")
  327. END
  328. RETURN
  329.  
  330. gadget:
  331.     SELECT
  332.         WHEN in2 = activeGadget THEN DO
  333.         IF currentnode = "CURRENTNODE" THEN RETURN
  334.             counter = FIND(entries,currentnode)
  335.             Anz=WORDS(Eintraege3.counter)
  336.             Nummer=DELWORD(Eintraege3.counter,1,Anz-1)
  337.                 Nummer1=WORD(Eintraege2.Nummer,1)
  338.                 Nummer2=WORD(Eintraege2.Nummer,2)
  339.             DO i = Nummer1+1 TO Nummer2-1
  340.                 IF INDEX(startup.i,";") = 1 THEN startup.i = DELSTR(startup.i,1,1)
  341.             END
  342.             CALL GetInhalt(counter)
  343.             call getTextview(counter)
  344.             changes = 1
  345.  
  346.         END
  347.         WHEN in2 = deactiveGadget THEN DO
  348.         IF currentnode = "CURRENTNODE" THEN RETURN
  349.             counter = FIND(entries,currentnode)
  350.             Anz=WORDS(Eintraege3.counter)
  351.             Nummer=DELWORD(Eintraege3.counter,1,Anz-1)
  352.                 Nummer1=WORD(Eintraege2.Nummer,1)
  353.                 Nummer2=WORD(Eintraege2.Nummer,2)
  354.             DO i = Nummer1+1 TO Nummer2-1
  355.                 IF INDEX(startup.i,";") ~= 1 THEN IF startup.i ~= "" THEN startup.i = ";"||startup.i
  356.             END
  357.             CALL GetInhalt(counter)
  358.             call getTextview(counter)
  359.             changes = 1
  360.  
  361.         END
  362.         WHEN in2 = ToggleGadget THEN DO
  363.         IF currentnode = "CURRENTNODE" THEN RETURN
  364.             counter = FIND(entries,currentnode)
  365.             Anz=WORDS(Eintraege3.counter)
  366.             Nummer=DELWORD(Eintraege3.counter,1,Anz-1)
  367.                 Nummer1=WORD(Eintraege2.Nummer,1)
  368.                 Nummer2=WORD(Eintraege2.Nummer,2)
  369.             DO i = Nummer1+1 TO Nummer2-1
  370.                 IF INDEX(startup.i,";") = 1 THEN startup.i = DELSTR(startup.i,1,1)
  371.                             ELSE IF startup.i ~= "" THEN startup.i = ";"||startup.i
  372.             END
  373.             CALL GetInhalt(counter)
  374.             call getTextview(counter)
  375.             changes = 1
  376.  
  377.         END
  378.         WHEN in2 = RemoveGadget THEN DO
  379.         IF currentnode = "CURRENTNODE" THEN RETURN
  380.         call topipe('id 0 s 256')
  381.             counter = FIND(entries,currentnode)
  382.             Anz=WORDS(Eintraege3.counter)
  383.             Nummer=DELWORD(Eintraege3.counter,1,Anz-1)
  384.  
  385.                 Nummer1=WORD(Eintraege2.Nummer,1)
  386.                 Nummer2=WORD(Eintraege2.Nummer,2)+1
  387.  
  388.             CALL RXTR_STEMREMOVE(startup,nummer1,nummer2-nummer1)
  389.             CALL RXTR_STEMREMOVE(Eintraege,counter,1)
  390.             CALL RXTR_STEMREMOVE(Eintraege2,counter,1)
  391.  
  392.             Tempname = "T:USCleaner"
  393.             CALL RXTR_WRITEFILE(tempname,startup)
  394.  
  395.             CALL ReadUserStartup(Tempname)
  396.             CALL GetInhalt(counter)
  397.             call topipe('id' TextEditorID 'gt=""')
  398.  
  399.             IF counter >0 THEN DO
  400.                 call topipe('id' AssignListViewID 'removenode')
  401.                 entries = ""
  402.                 counter = 0
  403.             END
  404.  
  405.  
  406.             call getListView
  407.             call topipe2('id 'AssignListViewID 'read')
  408.             IF WORD(in,3) ~= 0 THEN DO
  409.                 CurrentNode = WORD(in,3)
  410.                 counter = FIND(entries,currentnode)
  411.                 call getTextview(counter)
  412.             END
  413.                 changes = 1
  414.                 ADDRESS COMMAND "Delete" Tempname "QUIET"
  415.         call topipe('id 0 s 512')
  416.         END
  417.  
  418.         WHEN in2 = CancelGadget THEN EXIT(0)
  419.         WHEN in2 = SaveGadget THEN DO
  420.             IF changes = 1 THEN DO
  421.             call topipe('id 0 s 256')
  422.  
  423.             requesterdata='`requestchoice "USCleaner Message"
  424. "Save changed user-startup?" "Yes|No"`'
  425.             CALL ShellResult(requesterdata)
  426.                 IF result = 1 THEN DO
  427.                     CALL RXTR_WRITEFILE(UserStartup,startup)
  428.                     CALL RXTR_SETPROTECTION(UserStartup,schutzbits)
  429.                     Changes = 0
  430.                 END
  431.             call topipe('id 0 s 512')
  432.             END
  433.         END
  434.  
  435.         WHEN in2 = AssignListViewID THEN DO
  436.             currentnode=in5        /* remember the curently selected node for future use...*/
  437.             counter = FIND(entries,currentnode)
  438.             CALL GetInhalt(counter)
  439.             call getTextview(counter)
  440.         END
  441.  
  442.     OTHERWISE
  443.         NOP
  444.     END
  445. RETURN
  446.  
  447. keystroke:
  448.     SELECT
  449.         WHEN in2 = 69 THEN IF quickend = "YES" THEN EXIT()
  450.         WHEN in2 = 76 | in2 = 62 THEN DO
  451.             call topipe('id 'AssignListViewID 'up')    /* Cursor up,  NUM 8 */
  452.  
  453.             call topipe2('id 'AssignListViewID 'read')
  454.             IF WORD(in,3) ~= 0 THEN DO
  455.                 CurrentNode = WORD(in,3)
  456.                 counter = FIND(entries,currentnode)
  457.                 call getTextview(counter)
  458.             END
  459.         END
  460.         WHEN in2 = 77 | in2 = 30 THEN DO
  461.             call topipe('id 'AssignListViewID 'down')    /* Cursor down,  NUM 2 */
  462.  
  463.             call topipe2('id 'AssignListViewID 'read')
  464.             IF WORD(in,3) ~= 0 THEN DO
  465.                 CurrentNode = WORD(in,3)
  466.                 counter = FIND(entries,currentnode)
  467.                 call getTextview(counter)
  468.             END
  469.         END
  470.         WHEN in2 = 61 THEN DO        /* Home */
  471.             call topipe2('id' AssignListViewID 'read')
  472.             check = WORD(in,3)
  473.                 LPos=WORD(entries,1)
  474.                 IF Lpos ~= check THEN DO
  475.                     call topipe('id' AssignListViewID 's' lpos)
  476.                     currentnode = LPos
  477.                     counter = FIND(entries,currentnode)
  478.                     call getTextview(counter)
  479.                 END
  480.         END
  481.  
  482.         WHEN in2 = 29 THEN DO        /* End */
  483.             call topipe2('id' AssignListViewID 'read')
  484.             check = WORD(in,3)
  485.                 LPos=WORD(entries,WORDS(entries))
  486.                 IF Lpos ~= check THEN DO
  487.                     call topipe('id' AssignListViewID 's' lpos)
  488.                     currentnode = LPos
  489.                     counter = FIND(entries,currentnode)
  490.                     call getTextview(counter)
  491.                 END
  492.         END
  493.  
  494.     OTHERWISE
  495.         NOP
  496.     END
  497. RETURN
  498.  
  499. bubble:
  500. /* get help gadget number*/
  501. newbub=arg(1)
  502. if newbub=-1 then newbub=0
  503. /* return if it has not changed*/
  504. if (bubbleon=newbub) then return()
  505. /* close old bubble if we have one*/
  506. if bubbleon~=0 then call  topipe('bubble')
  507. /* if its not a valid gadget kill count down to display*/
  508. if newbub=0 then delaybub=0
  509. /*else remeber mouse position and start new countdown*/
  510. else do
  511. bubx=in3
  512. buby=in4
  513. delaybub=3
  514. end
  515. return
  516.